// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-3-28 13:26:27
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   MediaStore.java

package org.water.garden.db;

import android.content.*;
import android.database.Cursor;
import android.graphics.*;
import android.net.Uri;
import android.os.Environment;
import android.provider.BaseColumns;
import android.util.Log;
import java.io.*;
import java.text.CollationKey;
import java.text.Collator;

// Referenced classes of package android.provider:
//            BaseColumns

public final class MediaStore
{
    public static final class Video
    {
        public static final class Media
            implements VideoColumns
        {

            public static Uri getContentUri(String volumeName)
            {
                return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/video/media").toString());
            }

            public static final Uri INTERNAL_CONTENT_URI = getContentUri("internal");
            public static final Uri EXTERNAL_CONTENT_URI = getContentUri("external");
            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/video";
            public static final String DEFAULT_SORT_ORDER = "title";


            public Media()
            {
            }
        }

        public static interface VideoColumns
            extends MediaColumns
        {

            public static final String DURATION = "duration";
            public static final String ARTIST = "artist";
            public static final String ALBUM = "album";
            public static final String RESOLUTION = "resolution";
            public static final String DESCRIPTION = "description";
            public static final String IS_PRIVATE = "isprivate";
            public static final String TAGS = "tags";
            public static final String CATEGORY = "category";
            public static final String LANGUAGE = "language";
            public static final String THUMB_DATA = "mini_thumb_data";
            public static final String LATITUDE = "latitude";
            public static final String LONGITUDE = "longitude";
            public static final String DATE_TAKEN = "datetaken";
        }


        public static final Cursor query(ContentResolver cr, Uri uri, String projection[])
        {
            return cr.query(uri, projection, null, null, "name ASC");
        }

        public static final String DEFAULT_SORT_ORDER = "name ASC";

        public Video()
        {
        }
    }

    public static final class Audio
    {
        public static final class Albums
            implements BaseColumns, AlbumColumns
        {

            public static Uri getContentUri(String volumeName)
            {
                return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/audio/albums").toString());
            }

            public static final Uri INTERNAL_CONTENT_URI = getContentUri("internal");
            public static final Uri EXTERNAL_CONTENT_URI = getContentUri("external");
            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/albums";
            public static final String ENTRY_CONTENT_TYPE = "vnd.android.cursor.item/album";
            public static final String DEFAULT_SORT_ORDER = "album_key";


            public Albums()
            {
            }
        }

        public static interface AlbumColumns
        {

            public static final String ALBUM = "album";
            public static final String ALBUM_KEY = "album_key";
        }

        public static final class Artists
            implements BaseColumns, ArtistColumns
        {

            public static Uri getContentUri(String volumeName)
            {
                return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/audio/artists").toString());
            }

            public static final Uri INTERNAL_CONTENT_URI = getContentUri("internal");
            public static final Uri EXTERNAL_CONTENT_URI = getContentUri("external");
            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/artists";
            public static final String ENTRY_CONTENT_TYPE = "vnd.android.cursor.item/artist";
            public static final String DEFAULT_SORT_ORDER = "artist_key";


            public Artists()
            {
            }
        }

        public static interface ArtistColumns
        {

            public static final String ARTIST = "artist";
            public static final String ARTIST_KEY = "artist_key";
            public static final String NUMBER_OF_ALBUMS = "number_of_albums";
            public static final String NUMBER_OF_TRACKS = "number_of_tracks";
        }

        public static final class Playlists
            implements BaseColumns, PlaylistsColumns
        {
            public static final class Members
                implements AudioColumns
            {

                public static final Uri getContentUri(String volumeName, String playlistId)
                {
                    return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/audio/playlists/").append(playlistId).append("/members").toString());
                }

                public static final String CONTENT_DIRECTORY = "members";
                public static final String AUDIO_ID = "audio_id";
                public static final String PLAYLIST_ID = "playlist_id";
                public static final String PLAY_ORDER = "play_order";
                public static final String DEFAULT_SORT_ORDER = "play_order";

                public Members()
                {
                }
            }


            public static Uri getContentUri(String volumeName)
            {
                return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/audio/playlists").toString());
            }

            public static final Uri INTERNAL_CONTENT_URI = getContentUri("internal");
            public static final Uri EXTERNAL_CONTENT_URI = getContentUri("external");
            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/playlist";
            public static final String ENTRY_CONTENT_TYPE = "vnd.android.cursor.item/playlist";
            public static final String DEFAULT_SORT_ORDER = "name";


            public Playlists()
            {
            }
        }

        public static interface PlaylistsColumns
        {

            public static final String NAME = "name";
            public static final String DATA = "_data";
            public static final String TIMESTAMP = "timestamp";
        }

        public static final class Genres
            implements BaseColumns, GenresColumns
        {
            public static final class Members
                implements AudioColumns
            {

                public static final Uri getContentUri(String volumeName, long genreId)
                {
                    return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/audio/genres/").append(genreId).append("/members").toString());
                }

                public static final String CONTENT_DIRECTORY = "members";
                public static final String DEFAULT_SORT_ORDER = "title";
                public static final String AUDIO_ID = "audio_id";
                public static final String GENRE_ID = "genre_id";

                public Members()
                {
                }
            }


            public static Uri getContentUri(String volumeName)
            {
                return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/audio/genres").toString());
            }

            public static final Uri INTERNAL_CONTENT_URI = getContentUri("internal");
            public static final Uri EXTERNAL_CONTENT_URI = getContentUri("external");
            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/genre";
            public static final String ENTRY_CONTENT_TYPE = "vnd.android.cursor.item/genre";
            public static final String DEFAULT_SORT_ORDER = "name";


            public Genres()
            {
            }
        }

        public static interface GenresColumns
        {

            public static final String NAME = "name";
        }

        public static final class Media
            implements AudioColumns
        {

            public static Uri getContentUri(String volumeName)
            {
                return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/audio/media").toString());
            }

            public static Uri getContentUriForPath(String path)
            {
                return path.startsWith(Environment.getExternalStorageDirectory().getPath()) ? EXTERNAL_CONTENT_URI : INTERNAL_CONTENT_URI;
            }

            public static final Uri INTERNAL_CONTENT_URI = getContentUri("internal");
            public static final Uri EXTERNAL_CONTENT_URI = getContentUri("external");
            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/audio";
            public static final String DEFAULT_SORT_ORDER = "title";


            public Media()
            {
            }
        }

        public static interface AudioColumns
            extends MediaColumns
        {

            public static final String TITLE_KEY = "title_key";
            public static final String DURATION = "duration";
            public static final String ARTIST = "artist";
            public static final String ARTIST_KEY = "artist_key";
            public static final String SUMMARY = "summary";
            public static final String COMPOSER = "composer";
            public static final String ALBUM = "album";
            public static final String ALBUM_KEY = "album_key";
            public static final String ALBUM_ART = "album_art";
            public static final String TRACK = "track";
            public static final String YEAR = "year";
            public static final String IS_MUSIC = "is_music";
            public static final String IS_RINGTONE = "is_ringtone";
            public static final String IS_ALARM = "is_alarm";
        }


        public static String keyFor(String name)
        {
            if(name != null)
            {
                if(name.equals("<unknown>"))
                    return "\001";
                name = name.trim().toLowerCase();
                if(name.startsWith("the "))
                    name = name.substring(4);
                if(name.startsWith("an "))
                    name = name.substring(3);
                if(name.startsWith("a "))
                    name = name.substring(2);
                if(name.endsWith(", the") || name.endsWith(",the") || name.endsWith(", an") || name.endsWith(",an") || name.endsWith(", a") || name.endsWith(",a"))
                    name = name.substring(0, name.lastIndexOf(','));
                name = name.replaceAll("['.,?!]", "").trim();
                if(name.length() > 0)
                {
                    if(mColl == null)
                    {
                        mColl = Collator.getInstance();
                        mColl.setStrength(0);
                    }
                    try
                    {
                        StringBuilder b = new StringBuilder();
                        b.append('.');
                        int nl = name.length();
                        for(int i = 0; i < nl; i++)
                        {
                            b.append(name.charAt(i));
                            b.append('.');
                        }

                        name = b.toString();
                        byte arr[] = mColl.getCollationKey(name).toByteArray();
                        int len = arr.length;
                        if(arr[arr.length - 1] != 0)
                            Log.d("MediaStore", "Unexpected collation key format, new ICU?");
                        else
                            len--;
                        name = new String(arr, 0, len, "iso8859-1");
                    }
                    catch(UnsupportedEncodingException ex)
                    {
                        Log.e("MediaStore", "The unthinkable happened, new ICU?");
                        name = "";
                    }
                    return name;
                } else
                {
                    return "";
                }
            } else
            {
                return null;
            }
        }

        private static Collator mColl = null;


        public Audio()
        {
        }
    }

    public static final class Images
    {
        public static class Thumbnails
            implements BaseColumns
        {

            public static final Cursor query(ContentResolver cr, Uri uri, String projection[])
            {
                return cr.query(uri, projection, null, null, "image_id ASC");
            }

            public static final Cursor queryMiniThumbnails(ContentResolver cr, Uri uri, int kind, String projection[])
            {
                return cr.query(uri, projection, (new StringBuilder()).append("kind = ").append(kind).toString(), null, "image_id ASC");
            }

            public static final Cursor queryMiniThumbnail(ContentResolver cr, long origId, int kind, String projection[])
            {
                return cr.query(EXTERNAL_CONTENT_URI, projection, (new StringBuilder()).append("image_id = ").append(origId).append(" AND ").append("kind").append(" = ").append(kind).toString(), null, null);
            }

            public static Uri getContentUri(String volumeName)
            {
                return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/images/thumbnails").toString());
            }

            public static final Uri INTERNAL_CONTENT_URI = getContentUri("internal");
            public static final Uri EXTERNAL_CONTENT_URI = getContentUri("external");
            public static final String DEFAULT_SORT_ORDER = "image_id ASC";
            public static final String DATA = "_data";
            public static final String IMAGE_ID = "image_id";
            public static final String KIND = "kind";
            public static final int MINI_KIND = 1;
            public static final int FULL_SCREEN_KIND = 2;
            public static final int MICRO_KIND = 3;
            public static final String WIDTH = "width";
            public static final String HEIGHT = "height";


            public Thumbnails()
            {
            }
        }

        public static final class Media
            implements ImageColumns
        {

            public static final Cursor query(ContentResolver cr, Uri uri, String projection[])
            {
                return cr.query(uri, projection, null, null, "name ASC");
            }

            public static final Cursor query(ContentResolver cr, Uri uri, String projection[], String where, String orderBy)
            {
                return cr.query(uri, projection, where, null, orderBy != null ? orderBy : "name ASC");
            }

            public static final Bitmap getBitmap(ContentResolver cr, Uri url)
                throws FileNotFoundException, IOException
            {
                InputStream input = cr.openInputStream(url);
                Bitmap bitmap = BitmapFactory.decodeStream(input);
                input.close();
                return bitmap;
            }

            public static final String insertImage(ContentResolver cr, String imagePath, String name, String description)
                throws FileNotFoundException
            {
                FileInputStream stream = new FileInputStream(imagePath);
                return insertImage(cr, BitmapFactory.decodeFile(imagePath), name, description);
            }

            private static final Bitmap StoreThumbnail(ContentResolver cr, Bitmap source, long id, float width, float height, int kind)
            {
                try {
					Bitmap thumb;
					Uri url;
					Matrix matrix = new Matrix();
					float scaleX = width / (float)source.getWidth();
					float scaleY = height / (float)source.getHeight();
					matrix.setScale(scaleX, scaleY);
					thumb = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
					ContentValues values = new ContentValues(4);
					values.put("kind", Integer.valueOf(kind));
					values.put("image_id", Integer.valueOf((int)id));
					values.put("height", Integer.valueOf(thumb.getHeight()));
					values.put("width", Integer.valueOf(thumb.getWidth()));
					url = cr.insert(Thumbnails.EXTERNAL_CONTENT_URI, values);
					OutputStream thumbOut = cr.openOutputStream(url);
					thumb.compress(android.graphics.Bitmap.CompressFormat.JPEG, 100, thumbOut);
					thumbOut.close();
					return thumb;
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return null;
				}
            }

            public static final String insertImage(ContentResolver cr, Bitmap source, String title, String description)
            {

                return null;
            }

            public static Uri getContentUri(String volumeName)
            {
                return Uri.parse((new StringBuilder()).append("content://media/").append(volumeName).append("/images/media").toString());
            }

            public static final Uri INTERNAL_CONTENT_URI = getContentUri("internal");
            public static final Uri EXTERNAL_CONTENT_URI = getContentUri("external");
            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/image";
            public static final String DEFAULT_SORT_ORDER = "name ASC";


            public Media()
            {
            }
        }

        public static interface ImageColumns
            extends MediaColumns
        {

            public static final String DESCRIPTION = "description";
            public static final String WIDTH = "width";
            public static final String HEIGHT = "height";
            public static final String PICASA_ID = "picasa_id";
            public static final String THUMB_DATA = "mini_thumb_data";
            public static final String IS_PRIVATE = "isprivate";
            public static final String LATITUDE = "latitude";
            public static final String LONGITUDE = "longitude";
            public static final String DATE_TAKEN = "datetaken";
            public static final String ORIENTATION = "orientation";
        }


        public Images()
        {
        }
    }

    public static interface MediaColumns
        extends BaseColumns
    {

        public static final String DATA = "_data";
        public static final String TITLE = "title";
        public static final String TIMESTAMP = "timestamp";
        public static final String MIME_TYPE = "mime_type";
        public static final String DRM_CONTENT_TYPE = "drm_content_type";
        public static final String DRM_TYPE = "drm_type";
        public static final String DRM_TYPE_OMA_1 = "oma1";
    }


    public MediaStore()
    {
    }

    private static final String TAG = "MediaStore";
}